from django.db import models
from datetime import datetime

# 用户表
class UserModel(models.Model):
    username = models.CharField(max_length=32)
    mobile = models.CharField(max_length=11)
    password = models.CharField(max_length=256)
    account = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    user_card = models.CharField(max_length=18,default='',verbose_name='身份证号码')
    user_type = models.IntegerField(default=0,verbose_name='1 为服务商 2 为商家')
    create_datetime = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.username
    class Meta:
        db_table = 'user'


#合同表
class ContractModel(models.Model):
    content = models.TextField()
    def __str__(self):
        return self.content
    class Meta:
        db_table = 'contract'

#用户签订合同
class UserContractModel(models.Model):
    user_id = models.IntegerField()
    contract_id = models.IntegerField()
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'user_contract'


#三方用户表
class ThirdUserModel(models.Model):
    user_id = models.IntegerField(default=0)
    token = models.CharField(max_length=256)
    uid = models.CharField(max_length=128)
    url = models.CharField(max_length=256)
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'third_user'

#专业表
class ProfessionModel(models.Model):
    profession_name = models.CharField(max_length=36,verbose_name='专业名称')
    def __str__(self):
        return self.profession_name
    class Meta:
        db_table = 'profession'

#服务商擅长专业表
class UserProfessionModel(models.Model):
    user_id = models.IntegerField(default=0)
    profession_id = models.IntegerField(default=0)
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'user_profession'


# 企业表
class CompaniesModel(models.Model):
    companies_name = models.CharField(max_length=32, verbose_name='企业名称')
    juridical_person = models.CharField(max_length=16, verbose_name='法人')
    mobile = models.CharField(max_length=11)
    address = models.CharField(max_length=64, verbose_name='企业地址')

    def __str__(self):
        return self.companies_name
    class Meta:
        db_table = 'company'

# 企业与个人关联表
class CompaniesUserModel(models.Model):
    user_id = models.IntegerField()
    companies_id = models.IntegerField()

    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'company_user'

#学校表
class SchoolModel(models.Model):
    school_name = models.CharField(max_length=36,verbose_name='学院名称')
    school_type = models.IntegerField(default=0,verbose_name='0 为专科 1 为本科')
    def __str__(self):
        return self.school_name
    class Meta:
        db_table = 'school'

#学院专业表
class SchoolProfessionModel(models.Model):
    professional = models.CharField(max_length=36, verbose_name='院系专业名称')
    sytstem_type = models.IntegerField(default=0, verbose_name='0 为 院系 1 为院系对应的专业')
    def __str__(self):
        return self.professional
    class Meta:
        db_table = 'school_profession'


#学院与用户表
class SchoolUserModel(models.Model):
    user_id = models.IntegerField()
    school_id = models.IntegerField()
    professional_id = models.IntegerField()
    create_time = models.DateField(verbose_name='入学时间')
    graduate_time = models.DateField(verbose_name='毕业时间')
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'school_user'


#服务商个人详细信息
class ServiceAbilityModel(models.Model):
    job_age = models.CharField(max_length=36,verbose_name='工作经验')
    introduce = models.TextField()
    user_id = models.IntegerField()
    create_datetime = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'service_ability'

#商家需求表
class BusinessDemandModel(models.Model):
    demand_name = models.CharField(max_length=128,verbose_name='商品需求')
    specific_detail = models.TextField()
    price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    settlement_type = models.IntegerField(default=0, verbose_name='1 为日结 2 为月结 3为完工结')
    business_type = models.IntegerField(default=0, verbose_name='1 为个人级 2 为企业级')
    profession_id = models.IntegerField(verbose_name='需求的标签')
    user_id = models.IntegerField()
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    create_datetime = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.demand_name
    class Meta:
        db_table = 'business_demand'

#用户接单
class TakeOrderModel(models.Model):
    user_id = models.IntegerField()
    business_id = models.IntegerField()
    create_datetime = models.DateTimeField(default=datetime.now())
    status = models.IntegerField(default=0,verbose_name='0 未交接 1 已完成 2 未通过')
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'take_order'


#商铺表
class ShopModel(models.Model):
    shop_name = models.CharField(max_length=32,verbose_name='商铺名')
    user_id = models.IntegerField()
    def __str__(self):
        return self.shop_name
    class Meta:
        db_table = 'shop'

#商品表
class GoodsModel(models.Model):
    goods_name = models.CharField(max_length=32,verbose_name='商品名')
    price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    goods_introduce = models.TextField(verbose_name='商品介绍')
    profession_id = models.IntegerField(default=0,verbose_name='商品所属专业类型外键')
    shop_id = models.IntegerField(verbose_name='商铺外键')
    user_id = models.IntegerField(verbose_name='商家个人外键')
    def __str__(self):
        return self.goods_name
    class Meta:
        db_table = 'goods'

#购物车表
class ShoppingCartModel(models.Model):
    user_id = models.IntegerField()
    shop_id = models.IntegerField()
    goods_id = models.IntegerField()
    goods_count = models.IntegerField()
    goods_price = models.DecimalField(max_digits=10,decimal_places=2)
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'shopping_cart'


#订单表
class OrderModel(models.Model):
    order_num = models.BigIntegerField(primary_key=True)
    user_id = models.IntegerField()
    seller_id = models.IntegerField(verbose_name='卖家id')
    goods_price = models.DecimalField(max_digits=10, decimal_places=2)
    pay_status = models.IntegerField(default=1, verbose_name='1 为未支付 2 为支付完成')
    create_time = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.order_num
    class Meta:
        db_table = 'order'

#订单历史记录表
class OrderRecordModel(models.Model):
    order_id = models.BigIntegerField()
    user_id = models.IntegerField(verbose_name='买家id')
    order_num = models.BigIntegerField(verbose_name='所属订单')
    seller_id = models.IntegerField(verbose_name='卖家id')
    shop_id = models.IntegerField(default=0,verbose_name='商铺外键')
    goods_count = models.IntegerField()
    goods_price = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())

    def __str__(self):
        return self.order_id

    class Meta:
        db_table = 'order_record'

#用户账户转入记录表
class UserDecreaseAccount(models.Model):
    money = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())
    user_id = models.IntegerField()

    def __str__(self):
        return self.money
    class Meta:
        db_table = 'decrease_account'


#用户账户转出记录表
class UserAddAccount(models.Model):
    money = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())
    user_id = models.IntegerField()

    def __str__(self):
        return self.money

    class Meta:
        db_table = 'add_account'
